package com.jj.net.codec;

import com.jj.message.battle.UserMessage;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageCodec;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

public class UserMessageCodec extends ByteToMessageCodec<UserMessage> {
    private static Logger logger = LoggerFactory.getLogger(UserMessage.class);

    private static boolean usingEnigma = true;

    @Override
    protected void encode(ChannelHandlerContext ctx, UserMessage msg, ByteBuf out) throws Exception {
        msg.write2ByteBuf(out);
    }

    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
        UserMessage ioMsg = UserMessage.parseFrom(in);
        out.add(ioMsg);
    }
}
